package com.yunshipei.core.common.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class AdapterConfigDbHelper extends SQLiteOpenHelper {

    private static final String DB_NAME = "xcloud_config.db";
    private static final int DB_VERSION = 3;

    public AdapterConfigDbHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table if not exists adapter_info(appId text not null unique, pac_name text not null,version text not null);");
        v2(db);
        v3(db);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        for (int i = oldVersion; i < newVersion; i++) {
            switch (i) {
                case 1:
                    v2(db);
                    break;
                case 2:
                    v3(db);
                    break;
            }
        }
    }

    /**
     * 版本2增加了一张运行时配置信息的表
     */
    private void v2(SQLiteDatabase db) {
        db.execSQL("create table if not exists runtime_engine_info(runtime_version text not null unique, enc_manager_server text not null);");
    }

    /**
     * 版本3增加小程序版本记录的表
     */
    private void v3(SQLiteDatabase db) {
        db.execSQL("create table if not exists universal_web_app_info(appId text not null unique, pkg_name text not null,version text not null);");
    }
}
